package com.example.nhdz;


import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.baselibrary.dialog.AlertDialog;
import com.example.baselibrary.http.HttpUtils;
import com.example.framelibrary.BaseSkinActivity;
import com.example.framelibrary.DefaultNavigationBar;
import com.example.framelibrary.HttpCallBack;
import com.example.framelibrary.http.OkHttpEngine;
import com.example.nhdz.bean.DiscoverListResult;

/**
 * @author 吴子玄
 */
public class MainActivity extends BaseSkinActivity implements View.OnClickListener {
    private Button btn, btn_dialog;

    @Override
    protected int getLayoutById() {
        return R.layout.activity_main;
    }

    @Override
    protected void initData() {
        HttpUtils.init(new OkHttpEngine());
        HttpUtils.with(this)
                .url("http://is.snssdk.com/2/essay/discovery/v3/")
                .cache(false)// 读取缓存
                .get()
                .addParam("iid","6152551759")
                .addParam("aid","7")
                .execute(
                new HttpCallBack<DiscoverListResult>() {
                    @Override
                    public void onError(Exception e) {

                    }

                    @Override
                    public void onSuccess(DiscoverListResult result) {
                        // 成功回掉这个方法
                        //　目前是没有缓存，现在有了数据库，还有了网络引擎
                        // 思路  某些接口如果需要缓存请自己带标示
                        System.out.println("=====DiscoverListResult==========");
                    }
                });

    }

    @Override
    protected void initViews() {
        btn = viewById(R.id.test_tv);
        btn_dialog = viewById(R.id.btn_dialog);
        btn.setOnClickListener(this);
        btn_dialog.setOnClickListener(this);
    }

    @Override
    protected void initTitle() {
        DefaultNavigationBar navigationBar = new
                DefaultNavigationBar.Builder(this)
                .setTitle("投稿")
                .builder();

    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.test_tv:
                Toast.makeText(this, "hello-world", Toast.LENGTH_SHORT).show();
                btn.setText("hello000");
                break;
            case R.id.btn_dialog:
                AlertDialog dialog = new AlertDialog.Builder(this)
                        .setContentView(R.layout.detail_comment_dialog)
                        .formBottom(true).fullWidth().show();


                // dialog去操作点击事件
                final EditText commentEt = dialog.getView(R.id.comment_editor);

                // 特有操作对象  getView方法   ListView  RecyclerView  CheckBox

                dialog.setOnclickListener(R.id.submit_btn, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Toast.makeText(MainActivity.this,
                                commentEt.getText().toString().trim(), Toast.LENGTH_LONG).show();
                    }
                });
                break;
            default:
                break;
        }
    }
}